import React from 'react';
import { Toast, } from 'antd-mobile';

export default class Index extends React.Component {
    constructor(props){
        super(props)
        this.state={
            type: props.match.params.type*1,  //1--银行卡  2--支付宝
            account_name: '',
            account: '',
            bank_name: '',
        }
    }
	componentDidMount(){
		document.title = '添加提现方式'
	}
	changeType(type){
		this.setState({
			type
		})
    }
    // 绑定
    bindType(){
        if(this.state.account_name===''){
            return Toast.fail('请输入账户姓名!',1)
        }
        if(this.state.type===1){
            if(this.state.bank_name===''){
                return Toast.fail('请输入开户行!',1)
            }
        }
        if(this.state.account===''){
            return Toast.fail('请输入账号!',1)
        }
        Toast.loading()
        var req={
            type: this.state.type,
            account_name: this.state.account_name,
            account: this.state.account,
            bank_name: this.state.bank_name,
        }
        global.Ajax.hhtc_request('tx/add',req).then(data=>{
            Toast.hide()
			if(data.code===1){
				Toast.success(data.msg,1,()=>{
                    this.props.history.goBack()
                })
			}else{
                Toast.fail(data.msg,1)
            }
		})
    }
	render(){
		return(
			<div className='bind_paytype_box'>
                <div className='tabs'>
                    <div className={this.state.type===2?'active':''} onClick={this.changeType.bind(this,2)}>
                        <img alt='' src={require('../../imgs/alipay.png')} />
                        <p>添加支付宝账户</p>
                    </div>
                    <div className={this.state.type===1?'active':''} onClick={this.changeType.bind(this,1)}>
                        <img alt='' src={require('../../imgs/card.png')} />
                        <p>添加银行卡账户</p>
                    </div>
                </div>
                {this.state.type===2?
                    <div className='bind_froms'>
                        <div className='item'>
                            <p>姓名</p>
                            <input type='text' placeholder='请输入姓名' onChange={(e)=>{
                                this.setState({
                                    account_name: e.target.value,
                                })
                            }} />
                        </div>
                        <div className='item'>
                            <p>支付宝账号</p>
                            <input type='text' placeholder='请输入支付宝账号' onChange={(e)=>{
                                this.setState({
                                    account: e.target.value,
                                })
                            }} />
                        </div>
                        <p className='sub' onClick={this.bindType.bind(this)}>确认添加</p>
                        <span>*请仔细核对您的账户信息，否则无法到账！</span>
                    </div>
                :
                    <div className='bind_froms'>
                        <div className='item'>
                            <p>持卡人姓名</p>
                            <input type='text' placeholder='请输入持卡人姓名' onChange={(e)=>{
                                this.setState({
                                    account_name: e.target.value,
                                })
                            }} />
                        </div>
                        <div className='item'>
                            <p>开户行</p>
                            <input type='text' placeholder='请输入开户行' onChange={(e)=>{
                                this.setState({
                                    bank_name: e.target.value,
                                })
                            }} />
                        </div>
                        <div className='item'>
                            <p>银行卡号</p>
                            <input type='number' placeholder='请输入银行卡号' onChange={(e)=>{
                                this.setState({
                                    account: e.target.value,
                                })
                            }} />
                        </div>
                        <p className='sub' onClick={this.bindType.bind(this)}>确认添加</p>
                        <span>*请仔细核对您的账户信息，否则无法到账！</span>
                    </div>
                }
			</div>
		)
	}
}
